#!/usr/bin python3
# -*- coding: utf-8 -*-

class LearnStatus:

    def __init__(self, n: int, s: list):
        self._s = s
        self._n = n

    def _status(self, start: int, end: int) -> int:
        temp = self._s[start:end + 1]
        return min(temp) * sum(temp)

    def best_statu(self):
        status = []
        for i in range(1, self._n + 1): # 时间长度
            for j in range(1, self._n - i + 2):
                for k in range(1, self._n - j + 1):
                    status.append(self._status(j-1, k + i + 1))
        return max(status)


if __name__ == '__main__':
    n = int(input())

    s1 = [int(i) for i in input().split(' ')]

    status = LearnStatus(n, s1)
    res = status.best_statu()
    print(res)

